<script>
import { insertDepart } from '@/api/admin/depart.js'
import departRules from '@/rules/departRules.js'
export default {
  props: ['modelValue'],
  emits: ['update:modelValue', 'resetData'],
  computed: {
    flag: {
      get() {
        return this.modelValue
      },
      set(nv) {
        this.$emit('update:modelValue', nv)
      },
    },
  },
  data() {
    return {
      departRules,
      departData: {
        department_name: '',
      },
    }
  },

  methods: {
    async addNewDepart() {
      await this.$refs.form.validate()
      await insertDepart(this.departData)
      this.flag = false
      this.$emit('resetData')
    },
    resetFormData() {
      this.departData = {}
      this.$refs.form.resetFields()
    },
  },
}
</script>

<template>
  <el-dialog v-model="flag" title="系添加" width="600px" @closed="resetFormData">
    <el-form label-width="80px" :inline="false" ref="form" :model="departData" :rules="departRules">
      <el-form-item label="系名称" prop="department_name">
        <el-input type="text" v-model="departData.department_name"></el-input>
      </el-form-item>
    </el-form>

    <template #footer>
      <el-button @click="$emit('update:modelValue', nv)">取消</el-button>
      <el-button type="primary" @click="addNewDepart()">新增</el-button>
    </template>
  </el-dialog>
</template>
